const Router = require('koa-router')
const User = require('../../../db/model/user')
const { RegisterValidator } = require('../../validator/validator')

const router = new Router({ prefix: '/v1/user' })

router.post('/register', async (ctx) => {
  const v = await new RegisterValidator().validate(ctx)

  const user = {
    nickname: v.get('body.nickname'),
    email: v.get('body.email'),
    password: v.get('body.password2')
  }

  await User.create(user)
  throw new global.errs.Success()
  
})

module.exports = router